package com.ruoyi.sales.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sales.domain.ZcStoreInfo;
import com.ruoyi.sales.service.IZcStoreInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 仓库信息Controller
 * 
 * @author woo
 * @date 2024-04-08
 */
@RestController
@RequestMapping("/sales/storeInfo")
public class ZcStoreInfoController extends BaseController
{
    @Autowired
    private IZcStoreInfoService zcStoreInfoService;

    /**
     * 查询仓库信息列表
     */
    @PreAuthorize("@ss.hasPermi('sales:storeInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZcStoreInfo zcStoreInfo)
    {
        startPage();
        List<ZcStoreInfo> list = zcStoreInfoService.selectZcStoreInfoList(zcStoreInfo);
        for (ZcStoreInfo storeInfo : list) {
            Long wide = storeInfo.getWide();
            Long line = storeInfo.getLine();
            long l = wide * line;
            storeInfo.setProduceCount(String.valueOf(l));
        }
        return getDataTable(list);
    }

    /**
     * 导出仓库信息列表
     */
    @PreAuthorize("@ss.hasPermi('sales:storeInfo:export')")
    @Log(title = "仓库信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZcStoreInfo zcStoreInfo)
    {
        List<ZcStoreInfo> list = zcStoreInfoService.selectZcStoreInfoList(zcStoreInfo);
        ExcelUtil<ZcStoreInfo> util = new ExcelUtil<ZcStoreInfo>(ZcStoreInfo.class);
        util.exportExcel(response, list, "仓库信息数据");
    }

    /**
     * 获取仓库信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('sales:storeInfo:query')")
    @GetMapping(value = "/{storeId}")
    public AjaxResult getInfo(@PathVariable("storeId") Long storeId)
    {
        return success(zcStoreInfoService.selectZcStoreInfoByStoreId(storeId));
    }

    /**
     * 新增仓库信息
     */
    @PreAuthorize("@ss.hasPermi('sales:storeInfo:add')")
    @Log(title = "仓库信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZcStoreInfo zcStoreInfo)
    {
        return toAjax(zcStoreInfoService.insertZcStoreInfo(zcStoreInfo));
    }

    /**
     * 修改仓库信息
     */
    @PreAuthorize("@ss.hasPermi('sales:storeInfo:edit')")
    @Log(title = "仓库信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZcStoreInfo zcStoreInfo)
    {
        return toAjax(zcStoreInfoService.updateZcStoreInfo(zcStoreInfo));
    }

    /**
     * 删除仓库信息
     */
    @PreAuthorize("@ss.hasPermi('sales:storeInfo:remove')")
    @Log(title = "仓库信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{storeIds}")
    public AjaxResult remove(@PathVariable Long[] storeIds)
    {
        return toAjax(zcStoreInfoService.deleteZcStoreInfoByStoreIds(storeIds));
    }
}
